package com.avic.rong.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.activity.ArticleDetailActivity;
import com.avic.rong.bean.show_bean.TypeBean;
import com.avic.rong.questionOrAnswer.activity.PersonalHomeActivity;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.example.minato.minastore.utils.GlideApp;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Creater: Created by wangyz on 2017/1/10.
 * Email: 936804097@qq.com
 */

public class PublicNumberAdapter extends RecyclerView.Adapter<PublicNumberAdapter.PublicNumberViewHolder> {


    private Context mContext;
    private List<TypeBean> data = new ArrayList<>();

    public PublicNumberAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<TypeBean> list){
        this.data = list;
        notifyDataSetChanged();
    }

    @Override
    public PublicNumberAdapter.PublicNumberViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.view_public_number, parent, false);
        PublicNumberViewHolder holder = new PublicNumberViewHolder(view, viewType);

        return holder;
    }

    @Override
    public void onBindViewHolder(PublicNumberAdapter.PublicNumberViewHolder holder, final int position) {

        GlideApp.with(mContext).load( data.get(position).getLogo())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .error(R.mipmap.deafult_image_header)
                .into(holder.img_category);

        if (data.get(position).getIsV()!=1) {
            holder.pub_image_daV.setVisibility(View.GONE);
        }
        holder.tv_category_name.setText(data.get(position).getUser_name());
        holder.img_category.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent PresenIntent = new Intent(mContext, PersonalHomeActivity.class);
                PresenIntent.putExtra("homeUserID", data.get(position).getUser_id() + "");
                mContext.startActivity(PresenIntent);
            }
        });
     //   holder.itemView.setOnClickListener(new CriterionItemOnClickListener(mContext, AppUtils.BASE_URL + "app/good/info/" + data.get(position) + ".html"));

    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    class PublicNumberViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.category_name_name)
        TextView tv_category_name;
        @BindView(R.id.img_category)
        ImageView img_category;
        private final ImageView pub_image_daV;

        public PublicNumberViewHolder(View itemView, int type) {
            super(itemView);
            pub_image_daV = itemView.findViewById(R.id.pub_image_daV);
            ButterKnife.bind(this, itemView);
        }
    }


}
